package com.ruoyi.chat.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.chat.domain.BookFileEntity;
import com.ruoyi.chat.dto.BookResp;
import com.ruoyi.chat.dto.ChatDtoReq;
import com.ruoyi.chat.mapper.BookFileMapper;
import com.ruoyi.common.utils.bean.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class BookService {

    @Resource
    BookFileMapper fileMapper;
    public List<BookResp> getBooks(ChatDtoReq req) {
        log.info("书籍开始处理");
        log.info("req:{}",req);
        QueryWrapper<BookFileEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name",req.getMessage());
        List<BookFileEntity> games = fileMapper.selectList(queryWrapper);
        List<BookResp> resp=  new ArrayList<>();
        games.forEach(gameFileEntity -> {
            BookResp bookResp = new BookResp();
            BeanUtils.copyProperties(gameFileEntity,bookResp);
            bookResp.setPublicUrl(gameFileEntity.getDomainPrefix()+gameFileEntity.getRelativePath());
            bookResp.setLanUrl(gameFileEntity.getLocalPrefix()+gameFileEntity.getRelativePath());
            resp.add(bookResp);
        });
        return resp;
    }
}
